package com.speechb.common.text;

import java.util.regex.Pattern;

/**
 * @author : llj
 * @version :2.1.0
 * @date : 2020/4/8 21:08
 */
public class CheckUtils {
    public static final Pattern NUM_PATTERN = Pattern.compile("^[0-9]*$");
    public static final Pattern PASSWORD_PATTERN = Pattern.compile("^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)[a-zA-Z0-9\\S]{6,20}$");
    public static final Pattern USERNAME_PATTERN = Pattern.compile("[a-zA-Z0-9]{4,20}$");


    /**
     * 利用正则表达式判断字符串是否是数字
     * @param num
     * @return
     */
    public static boolean isNumeric(String num) {
        return check(NUM_PATTERN, num);
    }

    public static boolean checkPassword(String password) {
        return check(PASSWORD_PATTERN, password);
    }

    public static boolean checkUserName(String username) {
        return check(USERNAME_PATTERN, username);
    }
    private static boolean check(Pattern pattern, String content) {
        if (pattern == null || content == null) {
            return false;
        }
        return pattern.matcher(content).matches();
    }
}
